var pageii = null;
var grid = null;
$(function() {

	grid = lyGrid({
		pagId : 'paging',
		l_column : [{
			colkey : "client_no",
			name : "客户"
		}, {
			colkey : "outReceiptNo",
			name : "送货单号"
		}, {
			colkey : "handplayNumber",
			name : "手工单号"
		},{
			colkey : "contract_num",
			name : "合同编号"
		},{
			colkey : "client_encode",
			name : "客户物料代码"
		},{
			colkey : "material_code",
			name : "物料编码"
		},{
			colkey : "warehouse",
			name : "仓位"
		},{
			colkey : "productName",
			name : "产品名称"
		},{
			colkey : "outDate",
			name : "出货日期"
		},{
			colkey : "number",
			name : "出货数量"
		},{
			colkey : "actualDelivery",
			name : "回单数量"
		},{
			colkey : "loss",
			name : "扣损耗"
		},{
			colkey : "lossRate",
			name : "扣损耗率"
		},{
			colkey : "clientLoss",
			name : "客户耗率"
		}],
		jsonUrl : rootPath + '/finance/loss_findByPage.shtml',
		dymCol:true,
		checkbox : true,
		serNumber : false
	});
	$("#addFun").click("click", function() {
		addAccount();
	});
	$("#editFun").click("click", function() {
		editAccount();
	});
	$("#delFun").click("click", function() {
		delAccount();
	});
	$("#search").click("click", function() {// 绑定查询按扭
		
		var searchParams = $("#searchForm").serializeJson();
		grid.setOptions({
			data : searchParams
		});
	});
	
});
function editAccount() {
	var cbox = grid.getSelectedCheckbox();
	if (cbox.length > 1 || cbox == "") {
		layer.msg("只能选中一个");
		return;
	}
	pageii = layer.open({
		title : "编辑物料",
		type : 2,
		area : [ "800px", "100%" ],
		content : rootPath + '/finance/loss_edit.shtml?id=' + cbox
	});
}
function addAccount() {
	pageii = layer.open({
		title : "新增物料",
		type : 2,
		area : [ "800px", "100%" ],
		content : rootPath + '/metals/metalsbom_addUI.shtml'
	});
}
function delAccount() {
	var cbox = grid.getSelectedCheckbox();
	if (cbox == "") {
		layer.msg("请选择删除项！！");
		return;
	}
	layer.confirm('是否删除？', function(index) {
		var url = rootPath + '/finance/loss_deleteEntity.shtml';
		var s = CommnUtil.ajax(url, {
			ids : cbox.join(",")
		}, "json");
		if (s == "success") {
			layer.msg('删除成功');
			grid.loadData();
		} else {
			layer.msg('删除失败');
		}
	});
}
